#include "../../src/queue.h"
#include "../unity/unity.h"
#include "../unity/unity_internals.h"

#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

static void test_queue_initialization(void) 
{
    Queue q;
	
    initQueue(&q);
    TEST_ASSERT_EQUAL(1, getSize(&q));
}

static void test_enqueue(void) 
{
    Queue q;
    initQueue(&q);
	
    enqueue(&q, 10);
    TEST_ASSERT_EQUAL_INT32(1, getSize(&q));
	
    enqueue(&q, 20);
    TEST_ASSERT_EQUAL_UINT32(2, getSize(&q));
}

static void test_dequeue(void) 
{
    Queue q;
    int value;
	
    initQueue(&q);
    enqueue(&q, 10);
    enqueue(&q, 20);
    dequeue(&q, &value);
    TEST_ASSERT(10 == value);
	
    TEST_ASSERT_EQUAL(1, getSize(&q));
	
    dequeue(&q, &value);
    TEST_ASSERT_EQUAL(20, value);
	
    TEST_ASSERT_EQUAL(0, getSize(&q));
}

static void test_queue_overflow(void) 
{
    Queue q;
    initQueue(&q);
    for (int i = 0; i < MAX_SIZE; i++) {
        TEST_ASSERT_EQUAL_INT32(0, enqueue(&q, i));
    }
    TEST_ASSERT_EQUAL_INT32(-1, enqueue(&q, 100)); // 队列已满
}

static void test_queue_underflow(void) 
{
    Queue q;
    int value;
	
    initQueue(&q);
    TEST_ASSERT_TRUE(-1 == dequeue(&q, &value)); // 队列为空
}

//////////////////////////////////////////////
void setUp(void) {
    // set stuff up here
}

void tearDown(void) {
    // clean stuff up here
}

int main(void) {
    UNITY_BEGIN();
    RUN_TEST(test_queue_initialization);
    RUN_TEST(test_enqueue);
    RUN_TEST(test_dequeue);
	RUN_TEST(test_queue_overflow);
	RUN_TEST(test_queue_underflow);
    return UNITY_END();
}